package com.ymatou.iapi.livebuyer.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.LiveRoomInfo;
import com.ymatou.iapi.livebuyer.parameter.QueryLiveRoomByIdsBean;
import com.ymatou.iapi.livebuyer.service.QueryLiveRoomByIdsCall;
import com.ymatou.iapi.liveseller.parameter.CreateLiveActivityBean;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.liveseller.parameter.ModifyLiveActivityBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmongosync.service.MongocrudCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductActivityStockWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.YMTDateUtil;

/**
 * 根据直播间Id批量查询直播间列表 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_QueryLiveRoomByIds {
	private static QueryLiveRoomByIdsBean queryliveroombyidsBean;
	private static QueryLiveRoomByIdsCall queryliveroombyidsCall;
	private static Integer liveroomid;
	private static LiveRoomWapper liveRoomWapper;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据直播间Id批量查询直播间列表");
		liveRoomWapper=new LiveRoomWapper();
	}

	@Before
	public void caseUp() {
		queryliveroombyidsBean = new QueryLiveRoomByIdsBean();
		queryliveroombyidsCall = new QueryLiveRoomByIdsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(queryliveroombyidsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void verifyDB(LiveRoomInfo liveRoomInfo) {
		LiveRoom liveroom = new LiveRoomWapper().selectLiveRoomById(liveRoomInfo.getLiveId());
		Logger.verifyEquals(liveroom.getStartTime().substring(0,19), liveRoomInfo.getStartTime(), "验证StartTime");
		Logger.verifyEquals(liveroom.getCreateTime().substring(0, 19), liveRoomInfo.getCreateTime(), "验证CreateTime");
		Logger.verifyEquals(liveroom.getGroupId(), liveRoomInfo.getGroupId(), "验证GroupId");
		Logger.verifyEquals(liveroom.getHistoryPlayUrl(), liveRoomInfo.getHistoryPlayUrl(), "验证HistoryPlayUrl");
		Logger.verifyEquals(liveroom.getLiveCover(), liveRoomInfo.getLiveCover(), "验证LiveCover");
		Logger.verifyEquals(liveroom.getId(), liveRoomInfo.getLiveId(), "验证LiveId");
		Logger.verifyEquals(liveroom.getLiveCategoryId(), liveRoomInfo.getLiveCategoryId(), "验证getLiveCategoryId");
		// 修改status
		if (liveroom.getLiveStatus() == 0) {
			if (liveroom.getStartTime().compareTo(YMTDateUtil.getSysTime()) < 0) {
				Logger.verifyEquals(1, liveRoomInfo.getLiveStatus(), "验证LiveStatus");
			} else {
				Logger.verifyEquals(liveroom.getLiveStatus(), liveRoomInfo.getLiveStatus(), "验证LiveStatus");
			}
		}

		Logger.verifyEquals(liveroom.getLiveTitle(), liveRoomInfo.getLiveTitle(), "验证LiveTitle");
		Logger.verifyEquals(liveroom.getPlayUrl(), liveRoomInfo.getPlayUrl(), "验证PlayUrl");
		if (liveRoomInfo.getPreVideo() != null) {
			Logger.verifyEquals(liveroom.getPreVideoHeight(), liveRoomInfo.getPreVideo().getPreVideoHeight(), "验证getPreVideoHeight");
			Logger.verifyEquals(liveroom.getPreVideoLength(), liveRoomInfo.getPreVideo().getPreVideoLength(), "验证getPreVideoLength");
			Logger.verifyEquals(liveroom.getPreVideoUrl(), liveRoomInfo.getPreVideo().getPreVideoUrl(), "验证getPreVideoUrl");
			Logger.verifyEquals(liveroom.getPreVideoWidth(), liveRoomInfo.getPreVideo().getPreVideoWidth(), "验证getPreVideoWidth");
		}
		Logger.verifyEquals(liveroom.getUserId(), liveRoomInfo.getUserId(), "验证UserId");
		Logger.verifyEquals(liveroom.getLiveDesc(), liveRoomInfo.getLiveDesc(), "验证LiveDesc");
		Logger.verifyEquals(liveroom.getPutawayCount(), liveRoomInfo.getPutawayCount(), "验证PutawayCount");
		Logger.verifyEquals(liveroom.getAction(), liveRoomInfo.getAction(), "验证Action");
		Logger.verifyEquals(false, liveRoomInfo.getInSecKill(), "验证InSecKill");
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryLiveRoomByIds_001() {
		Logger.start(true, "根据直播间Id批量查询直播间列表成功");
		try {
			if (liveroomid == null) {
				CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
				LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
				liveroomid = livedto.getId();
			}
			List<Integer> list = Arrays.asList(liveroomid);
			queryliveroombyidsBean.setLiveIdList(list);
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			ArrayList<LiveRoomInfo> liveroominfolist = queryliveroombyidsCall.getLiveRoomInfo();
			for (LiveRoomInfo liveRoomInfo : liveroominfolist) {
				verifyDB(liveRoomInfo);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_QueryLiveRoomByIds_002() {
		Logger.start(true, "不输入LiveId失败");
		try {
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("100", queryliveroombyidsCall.getString("code"), "判断code");
			Logger.verifyIsContains("直播Id列表不能为空", queryliveroombyidsCall.getString("message"), "判断message");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_QueryLiveRoomByIds_003() {
		Logger.start(true, "输入多个LiveId成功");
		try {
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			if (liveroomid == null) {
				LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
				liveroomid = livedto.getId();
			}
			initcreatebean.getLiveDto().setGroupId(String.valueOf(YMTDateUtil.getDate().getTime()));
			int liveroomid2=LiveRoomCallService.CreateSellerLive(initcreatebean).getId();
			List<Integer> list = Arrays.asList(liveroomid,liveroomid2);
			queryliveroombyidsBean.setLiveIdList(list);
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			ArrayList<LiveRoomInfo> liveroominfolist = queryliveroombyidsCall.getLiveRoomInfo();
			for (LiveRoomInfo liveRoomInfo : liveroominfolist) {
				verifyDB(liveRoomInfo);
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_QueryLiveRoomByIds_004() {
		Logger.start(true, "输入不存在LiveId失败");
		try {	
			List<Integer> list = Arrays.asList(-1);
			queryliveroombyidsBean.setLiveIdList(list);
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			Logger.verifyIsContains(0, queryliveroombyidsCall.getLiveRoomInfo().size(), "判断data数组返回为空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_QueryLiveRoomByIds_005() {
		Logger.start(true, "根据直播间Id批量查询删除直播间列表成功");
		try {
			if (liveroomid == null) {
				CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
				LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
				liveroomid = livedto.getId();
			}
			liveRoomWapper.updateLiveRoomAction(liveroomid, -1);
			List<Integer> list = Arrays.asList(liveroomid);
			queryliveroombyidsBean.setLiveIdList(list);
			queryliveroombyidsBean.setNoCache(true);
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			ArrayList<LiveRoomInfo> liveroominfolist = queryliveroombyidsCall.getLiveRoomInfo();
			for (LiveRoomInfo liveRoomInfo : liveroominfolist) {
				verifyDB(liveRoomInfo);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@Ignore
	//需要手动修改数据库查看缓存生效
	public void Tc_QueryLiveRoomByIds_006() {
		Logger.start(true, "根据直播间Id批量查询直播间列表成功,修改直播信息-有緩存");
		try {
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			liveroomid = livedto.getId();
			List<Integer> list = Arrays.asList(liveroomid);
			queryliveroombyidsBean.setLiveIdList(list);
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			ArrayList<LiveRoomInfo> liveroominfolist = queryliveroombyidsCall.getLiveRoomInfo();
			for (LiveRoomInfo liveRoomInfo : liveroominfolist) {
				verifyDB(liveRoomInfo);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_QueryLiveRoomByIds_007() {
		Logger.start(true, "根据直播间Id批量查询直播间列表成功-无緩存");
		try {
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			liveroomid = livedto.getId();
			List<Integer> list = Arrays.asList(liveroomid);
			queryliveroombyidsBean.setLiveIdList(list);
			queryliveroombyidsBean.setNoCache(true);
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			ArrayList<LiveRoomInfo> liveroominfolist = queryliveroombyidsCall.getLiveRoomInfo();
			for (LiveRoomInfo liveRoomInfo : liveroominfolist) {
				verifyDB(liveRoomInfo);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_QueryLiveRoomByIds_008() {
		Logger.start(true, "根据直播间Id批量查询直播间列表成功-正在秒杀-PRD1030-JIRACONN-25971");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 10 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			ModifyLiveActivityBean ModifyLiveActivityBean = LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), sellerId);
			Integer liveacctivityid = liveRoomWapper.selectLiveactivityByLiveId(createliveactivityBean.getLiveActivity().getLiveId()).get(0).getLiveActivityId();
			liveRoomWapper.updateLiveactivityStartTimeByLiveactivityid(liveacctivityid,  new Date(now.getTime()- 60 * 1000));
			liveroomid = createlive.getId();
			List<Integer> list = Arrays.asList(liveroomid);
			queryliveroombyidsBean.setLiveIdList(list);
			queryliveroombyidsBean.setNoCache(true);
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			ArrayList<LiveRoomInfo> liveroominfolist = queryliveroombyidsCall.getLiveRoomInfo();
			Logger.verifyEquals(true, liveroominfolist.get(0).getInSecKill(), "验证InSecKill");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	//inPreStartSecKill 15分钟内即将开始的秒杀活动才打标
	public void Tc_QueryLiveRoomByIds_009() {
		Logger.start(true, "根据直播间Id批量查询直播间列表成功-15分钟内秒杀inPreStartSecKill打标-售罄不打标");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 10 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			ModifyLiveActivityBean ModifyLiveActivityBean = LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), sellerId);
			
			liveroomid = createlive.getId();
			List<Integer> list = Arrays.asList(liveroomid);
			queryliveroombyidsBean.setLiveIdList(list);
			queryliveroombyidsBean.setNoCache(true);
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			ArrayList<LiveRoomInfo> liveroominfolist = queryliveroombyidsCall.getLiveRoomInfo();
//			Logger.verifyEquals(true, liveroominfolist.get(0).getInSecKill(), "验证InSecKill");
			Logger.verifyEquals(true, liveroominfolist.get(0).getInPreStartSecKill(), "验证inPreStartSecKill");
			//追加验证点 - 售罄不打标
			//TODO update liveactivityproduct set liveactivityproduct.ActivityStock = liveactivityproduct.SoldStock
			liveRoomWapper.updateLiveactivityByProduct(productId, 5, 5);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			liveroominfolist = queryliveroombyidsCall.getLiveRoomInfo();
			Logger.verifyEquals(false, liveroominfolist.get(0).getInPreStartSecKill(), "验证inPreStartSecKill");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	//inPreStartSecKill 15分钟内即将开始的秒杀活动才打标
	//20190613 修改规则-直播是否有15分钟内即将开始的秒杀活动打标或者已经开始离结算还差1分钟的秒杀活动 
	public void Tc_QueryLiveRoomByIds_010() {
		Logger.start(true, "根据直播间Id批量查询直播间列表成功-已经开始的秒杀inPreStartSecKill不打标-20190613修改规则");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 10 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			ModifyLiveActivityBean ModifyLiveActivityBean = LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), sellerId);
			Integer liveacctivityid = liveRoomWapper.selectLiveactivityByLiveId(createliveactivityBean.getLiveActivity().getLiveId()).get(0).getLiveActivityId();
			liveRoomWapper.updateLiveactivityStartTimeByLiveactivityid(liveacctivityid,  new Date(now.getTime() - 10 * 1000));
			liveroomid = createlive.getId();
			List<Integer> list = Arrays.asList(liveroomid);
			queryliveroombyidsBean.setLiveIdList(list);
			queryliveroombyidsBean.setNoCache(true);
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			ArrayList<LiveRoomInfo> liveroominfolist = queryliveroombyidsCall.getLiveRoomInfo();
//			Logger.verifyEquals(true, liveroominfolist.get(0).getInSecKill(), "验证InSecKill");
			Logger.verifyEquals(true, liveroominfolist.get(0).getInPreStartSecKill(), "验证inPreStartSecKill");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	//inPreStartSecKill 15分钟内即将开始的秒杀活动才打标
	public void Tc_QueryLiveRoomByIds_011() {
		Logger.start(true, "根据直播间Id批量查询直播间列表成功-15分钟后开始的秒杀inPreStartSecKill不打标");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 10 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			ModifyLiveActivityBean ModifyLiveActivityBean = LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), sellerId);
			Integer liveacctivityid = liveRoomWapper.selectLiveactivityByLiveId(createliveactivityBean.getLiveActivity().getLiveId()).get(0).getLiveActivityId();
			liveRoomWapper.updateLiveactivityStartTimeByLiveactivityid(liveacctivityid,  new Date(now.getTime()+ 16*60 * 1000));
			liveroomid = createlive.getId();
			List<Integer> list = Arrays.asList(liveroomid);
			queryliveroombyidsBean.setLiveIdList(list);
			queryliveroombyidsBean.setNoCache(true);
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			ArrayList<LiveRoomInfo> liveroominfolist = queryliveroombyidsCall.getLiveRoomInfo();
//			Logger.verifyEquals(true, liveroominfolist.get(0).getInSecKill(), "验证InSecKill");
			Logger.verifyEquals(false, liveroominfolist.get(0).getInPreStartSecKill(), "验证inPreStartSecKill");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	//20190509 之前的版本此字段是true 修改后变成只有开始秒杀了InSecKill才是true
	public void Tc_QueryLiveRoomByIds_012() {
		Logger.start(true, "根据直播间Id批量查询直播间列表成功-正在秒杀-即将开始的秒杀活动InSecKill为false");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 10 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			ModifyLiveActivityBean ModifyLiveActivityBean = LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), sellerId);
//			Integer liveacctivityid = liveRoomWapper.selectLiveactivityByLiveId(createliveactivityBean.getLiveActivity().getLiveId()).get(0).getLiveActivityId();
//			liveRoomWapper.updateLiveactivityStartTimeByLiveactivityid(liveacctivityid,  new Date(now.getTime()- 60 * 1000));
			liveroomid = createlive.getId();
			List<Integer> list = Arrays.asList(liveroomid);
			queryliveroombyidsBean.setLiveIdList(list);
			queryliveroombyidsBean.setNoCache(true);
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			ArrayList<LiveRoomInfo> liveroominfolist = queryliveroombyidsCall.getLiveRoomInfo();
			Logger.verifyEquals(false, liveroominfolist.get(0).getInSecKill(), "验证InSecKill");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_QueryLiveRoomByIds_013() {
		Logger.start(true, "根据直播间Id批量查询直播间列表成功-查询直播热度");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 10 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), sellerId);
			Double Heat=1.3;
			LiveRoomCallService.setLiveHeat(createlive.getId(), Heat);
			Thread.sleep(10000);
//			Integer liveacctivityid = liveRoomWapper.selectLiveactivityByLiveId(createliveactivityBean.getLiveActivity().getLiveId()).get(0).getLiveActivityId();
//			liveRoomWapper.updateLiveactivityStartTimeByLiveactivityid(liveacctivityid,  new Date(now.getTime()- 60 * 1000));
			liveroomid = createlive.getId();
			List<Integer> list = Arrays.asList(liveroomid);
			queryliveroombyidsBean.setLiveIdList(list);
			queryliveroombyidsBean.setNoCache(true);
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			ArrayList<LiveRoomInfo> liveroominfolist = queryliveroombyidsCall.getLiveRoomInfo();
			Logger.verifyEquals(Heat, liveroominfolist.get(0).getHeat(), "验证heat");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_QueryLiveRoomByIds_014() {
		Logger.start(true, "根据直播间Id批量查询直播间列表成功-查询recommendProducts-秒杀优先-top第二");
		try {
			//第几个商品参加秒杀
			int scekillno=2;
			//第几个商品置顶
			int topno=4;
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 10 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), sellerId);
			
			
			List<String> ProductIdList=new ArrayList<>();
			for (int i = 0; i < 5; i++) {
				Logger.comment("创建商品");
				AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
				String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
				ProductIdList.add(productId);
			}
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, ProductIdList);
			
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(ProductIdList.get(scekillno)).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			LiveRoomCallService.SetLiveProductTop(createlive.getId(), ProductIdList.get(topno));
			
			Thread.sleep(2000);
			List<Integer> list = Arrays.asList(createlive.getId());
			queryliveroombyidsBean.setLiveIdList(list);
			queryliveroombyidsBean.setNoCache(true);
			queryliveroombyidsBean.setRecommendProducts(true);
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			ArrayList<LiveRoomInfo> liveroominfolist = queryliveroombyidsCall.getLiveRoomInfo();
			Logger.verifyEquals(2, liveroominfolist.get(0).getRecommendProducts().size(), "验证RecommendProducts露出数量");
			Logger.verifyEquals(ProductIdList.get(scekillno),liveroominfolist.get(0).getRecommendProducts().get(0).getProductId(), "验证RecommendProduct1-scekill");
			Logger.verifyEquals(true,liveroominfolist.get(0).getRecommendProducts().get(0).getInSecKill(), "验证RecommendProduct1-getInSecKill");
			Logger.verifyEquals(ProductIdList.get(topno),liveroominfolist.get(0).getRecommendProducts().get(1).getProductId(), "验证RecommendProduct2-top");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_QueryLiveRoomByIds_015() {
		Logger.start(true, "根据直播间Id批量查询直播间列表成功-查询recommendProducts-售罄不展示");
		try {
			//第几个商品参加秒杀
			int scekillno=2;
			//第几个商品置顶
			int topno=4;
			Integer stock=5;
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 10 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), sellerId);
			
			
			List<String> ProductIdList=new ArrayList<>();
			for (int i = 0; i < 5; i++) {
				Logger.comment("创建商品");
				AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
				addpro.getProduct().getCatalogList().remove(0);
				addpro.getProduct().getCatalogList().get(0).setStock(stock);
				String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
				ProductIdList.add(productId);
			}
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, ProductIdList);
			
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(ProductIdList.get(scekillno)).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Thread.sleep(1000);
			Logger.comment("创建秒杀活动");
			starttime = new Date(YMTDateUtil.getDate().getTime() + 1 * 1000);
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, stock, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			LiveRoomCallService.SetLiveProductTop(createlive.getId(), ProductIdList.get(topno));
			Thread.sleep(1000);
			Integer liveacctivityid = liveRoomWapper.selectLiveactivityByLiveId(createlive.getId()).get(0).getLiveActivityId();
			//更新活动库存
			ProductManagerCallServiceV2.updateActivityStock0AndSync(Arrays.asList(ProductIdList.get(scekillno)),liveacctivityid);
			Thread.sleep(5000);
			List<Integer> list = Arrays.asList(createlive.getId());
			queryliveroombyidsBean.setLiveIdList(list);
			queryliveroombyidsBean.setNoCache(true);
			queryliveroombyidsBean.setRecommendProducts(true);
			queryliveroombyidsCall.setData(queryliveroombyidsBean);
			queryliveroombyidsCall.callService();
			Logger.verifyEquals("200", queryliveroombyidsCall.getString("code"), "判断code");
			ArrayList<LiveRoomInfo> liveroominfolist = queryliveroombyidsCall.getLiveRoomInfo();
			Logger.verifyEquals(2, liveroominfolist.get(0).getRecommendProducts().size(), "验证RecommendProducts露出数量");
//			Logger.verifyEquals(ProductIdList.get(scekillno),liveroominfolist.get(0).getRecommendProducts().get(0).getProductId(), "验证RecommendProduct1-scekill");
//			Logger.verifyEquals(true,liveroominfolist.get(0).getRecommendProducts().get(0).getInSecKill(), "验证RecommendProduct1-getInSecKill");
			Logger.verifyEquals(ProductIdList.get(topno),liveroominfolist.get(0).getRecommendProducts().get(0).getProductId(), "验证RecommendProduct2-top");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}